package edu.moravian.entity;

import edu.moravian.math.Point2D;
import edu.moravian.math.Vector2D;

/**
 * This serves as a model for a BallEntity 
 * 
 * @author ronaghan
 */
public class BallEntity extends AbstractEntity
{
    private double radius;
    
    /**
     * Create a new ball entity 
     * 
     * @param initLoc the initial location 
     * @param initHeading the initial heading (expected as a normal vector)
     * @param initSpeed the initial speed 
     * @param initRadius the radius of the ball
     * @param initMass the mass of the ball
     */
    public BallEntity(Point2D initLoc, Vector2D initHeading, double initSpeed, double initRadius, double initMass)
    {
        this.location = initLoc;
        this.heading = initHeading.getNormalized();
        this.speed = initSpeed;
        this.radius = initRadius;
        this.mass = initMass;
    }

    /**
     * Get the balls radius 
     * 
     * @return radius 
     */
    @Override
    public double getRadius()
    {
        return radius;
    }
    
    
    /**
     * Modify the balls radius
     * 
     * @param radius 
     */
    public void setRadius(double radius)
    {
       this.radius = radius;
    }
    
    
    
    /**
     * Get the width of a ball(same as height)
     * 
     * @return the width of the ball
     */
    @Override
    public double getWidth()
    {
        return radius * 2.0;
    }
    
    
    
    /**
     * Ball entities are defined by radius, if you want to 
     * change the width, modify the radius
     * 
     * @param width 
     */
    @Override
    public void setWidth(double width)
    {
        throw new UnsupportedOperationException("Setting width is not supported by balls, use radius");
    }
    
    /**
     * Get the height of a ball(same as width)
     * 
     * @return the height of the ball
     */
    @Override
    public double getHeight()
    {
        return radius * 2.0;
    }
    
    /**
     * Ball entities are defined by radius, if you want to 
     * change the height, modify the radius
     * 
     * @param height 
     */
    @Override
    public void setHeight(double height)
    {
        throw new UnsupportedOperationException("Setting height is not supported by bals, use radius");
    }
    
    

  
    /**
     * Simply modify the current location based on the speed, heading 
     * and time passed 
     * 
     * @param delta the time passed
     */
    @Override
    public void update(double delta)
    {
        location.scalePlusEquals(speed * delta, heading);
    }
    
}



